package Util::OnlineService::OnlineService;
use Moose;
use namespace::autoclean;

has 'schema' => (
	is => 'rw',
	required => 1,
	isa => 'DBIx::Class::Schema',
);

sub get_service_num_by_university{
	my ($self,$university_id) = @_;

	return $self->schema->resultset('OnlineService')->search({'university_id' => $university_id},{})->first;
}

sub get_service_num_by_tuan{
	my ($self,$tuan_id) = @_;

	return $self->schema->resultset('OnlineService')->search({'tuan_id' => $tuan_id},{})->first;
}

sub create {
        my ($self,$univ_id ,$tuan_id ,$service_num) = @_;
        my $online_service = $self->schema->resultset('OnlineService')->create({
                        university_id => $univ_id,
                        tuan_id => $tuan_id,
                        service_num => $service_num
                        });
        return $online_service;
}

sub update_by_tuan {
        my ($self,$tuan_id,$service_num) = @_;
        my $online_service = $self->schema->resultset('OnlineService')->search({'tuan_id' => $tuan_id},{})->first();
        $online_service->update({
                        service_num => $service_num
                        });
        return $online_service;
}

__PACKAGE__->meta->make_immutable;

1;
